﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jitter.LinearMath;
using Microsoft.Xna.Framework;

namespace X13.Mapping
{
    public sealed class MinefieldPosition : IEquatable<MinefieldPosition>
    {
        //Fields
        public int X { get; set; }
        public int Y { get; set; }

        //Construct
        public MinefieldPosition(float X, float Y)
        {
            this.X = (int)X;
            this.Y = (int)Y;
        }
                
        //Methods
        public static Vector2 Distance(MinefieldPosition a, MinefieldPosition b)
        {
            return b - a;
        }

        //implicits
        public static implicit operator Vector2(MinefieldPosition p)
        {
            return new Vector2(p.X, p.Y);
        }
        public static implicit operator MinefieldPosition(Vector2 p)
        {
            return new MinefieldPosition(p.X, p.Y);
        }

        public static implicit operator Vector3(MinefieldPosition p)
        {
            return new Vector3(p.X * Globals.MineTileScale.X, 0, p.Y * Globals.MineTileScale.Z);
        }
        public static implicit operator MinefieldPosition(Vector3 p)
        {
            return new MinefieldPosition(p.X / Globals.MineTileScale.X, p.Z / Globals.MineTileScale.Z);
        }

        public static implicit operator JVector(MinefieldPosition p)
        {
            return new JVector(p.X * Globals.MineTileScale.X, 0, p.Y * Globals.MineTileScale.Z);
        }
        public static implicit operator MinefieldPosition(JVector p)
        {
            return new MinefieldPosition(p.X / Globals.MineTileScale.X, p.Z / Globals.MineTileScale.Z);
        }
        
        public static MinefieldPosition operator +(MinefieldPosition a, MinefieldPosition b)
        {
            return new MinefieldPosition(a.X + b.X, a.Y + b.Y);
        }
        public static MinefieldPosition operator -(MinefieldPosition a, MinefieldPosition b)
        {
            return new MinefieldPosition(a.X - b.X, a.Y - b.Y);
        }
        public static MinefieldPosition operator *(MinefieldPosition a, float b)
        {
            return new MinefieldPosition(a.X * b, a.Y * b);
        }

        public bool Equals(MinefieldPosition other)
        {
            return (this.X == other.X) && (this.Y == other.Y);
        }
    }
}
